/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ex01;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 20060074
 */
public class InsertData {
    
    public static void main(String[] args) {
        
        Connection con = null;
        PreparedStatement pst = null;
                        
        try {   
            con =  DBUtils.openAcessConection("Northwind97");
            pst = con.prepareStatement("INSERT INTO Shippers (CompanyName, Phone) VALUES (?,?)");
                                    
            pst.setString(1, "Empresa XPTO");
            pst.setString(2, "(123) 111-9831");			
            
            int res = pst.executeUpdate();
            
            if (res != 0 ){
                System.out.println("Registo inserido com sucesso!");
            }
        } catch (SQLException ex) {
            Logger.getLogger(InsertData.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println(ex.getMessage());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(InsertData.class.getName()).log(Level.SEVERE, null, ex);            
            System.out.println(ex.getMessage());
        } finally {
            try {
                if (pst != null) pst.close();
                if (con != null) con.close();
            } catch (SQLException ex) {
                System.out.println(ex);
            } 
        } 
                              
       
        
    }

}
